package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class WaURLService {
    private static final Logger LOGGER = LoggerFactory.getLogger(WaURLService.class);

    @Autowired
    private Environment env;

    @Autowired
    RedisCache redisCache;

    public String getContactNumberURL(String contactNumber, String key) {
        String url = env.getProperty(key);
        if (redisCache.hasKey("ipaddress:" + contactNumber)) {
            Object fromUrl = redisCache.getCacheObject("ipaddress:" + contactNumber);
            url = url.replace("127.0.0.1:3000", String.valueOf(fromUrl));
        } else {
            redisCache.setCacheObject("ipaddress:" + contactNumber, "127.0.0.1:3000", 360, TimeUnit.DAYS);
        }
        LOGGER.info("getContactNumberURL:" + url);
        return url;
    }
}
